
<script type="text/javascript">
    $(function(){

        $.get('/admin/getcategories',{},function(resp){
            $('.segment').find('.category').html(resp).css({'font-size':'10px',width:'auto',margin:0});
            var opt = $('.category').find('select option');
            $('.category').find('select').change(setCategory);
            opt.each(function(i,op){
                var data = $(op).parents('.category').attr('data-value');
                if(data == $(op).val()){
                    $(op).attr('selected','selected');
                }
            });
        });
        var pagesCount = $('#revpages').data('artcount');
        var pages = $('#revpages');
        $('.score').jRating({isDisabled:true,type:'small',rateMax:5});
        if(pagesCount > 10){
            $('#revpages').tabPagination();
        }else{pages.hide();}

        var visib = $('.visibility');
        var cat = $('.categories');
        $(visib).change(function(){visibility($(this));});
        cat.change(setCategory);

        var comments = $('.comments');
        comments.each(function(i,el){
            var elm = $(el);
            if(elm.text() > '0'){
                elm.attr('title','Просмотреть комментарии к статье').css({cursor:'pointer','text-decoration':'underline','font-weight':'bold'});
                elm.bind('click',getComments);

            }else{
                elm.css({cursor:'default','text-decoration':'none'});
                var img = $('<img>',{id:'imgcomment',src:'/images/nocomment.png',style:'vertical-align:middle;padding-right:3px;'}).attr('title','Комментариев нет');
                elm.parent().find('img').replaceWith(img);
            }
        });

//    console.log( $('*').length );

    });
    function getComments(){

        $(this).comments();
    }

    function setCategory(){

        var p = $.post('/admin/setcategories',{id:$(this).parent().attr('id'),option:$(this).val()});

    }
    function getCategories(elem){

        var sel,opt;
        var par = $(elem).parent().attr('id');
        var selected = $(elem).val();
        $.get('/admin/getcategories',{},function(resp){
            $(elem).parent().find('.category').append(resp);
        });
    }
    function visibility(vis){
        var data = {};
        $.each(vis,function(i,elm){
            data.id = $(vis).attr('id');
            data.value = $(vis).val();
            $.ajax({
                url:'/admin/site/setvisib',
                dataType:'JSON',
                type:'POST',
                data:data
            });
        });
    }
    function returnBack(){
        $('#comment-container').remove();
        $('#backward').remove();
        $('#tab').show();
    }
</script>

<?php if(isset($this->page[0])):?>

    <div id="container" style="height:750px;width:870px;overflow:hidden;">
        <?php foreach($this->page as $p):?>
            <?php if(isset($p)):?>
                <div id="<?=$p['article_id']?>" class="segment" style="border-bottom:1px solid #555;padding:5px 0;">
                    <div  id="image" style="padding:0 10px;word-wrap:break-word;"><img src="/images/articles/<?=$p['img']?>"  style="height:40px;vertical-align:middle;border-radius:3px;"/><span class="title" style="padding:10px;font-weight:bold;"><?=$p['title']?></span></div>

                    <span class="tabtext"><img src="/images/calendar.png" style="vertical-align:middle;padding:0 5px;" title="Дата создания"></span><span class="created"><?=$p['created_dt'];?></span>
                    | <span class="tabtext">Категория:</span><span id="<?=$p['article_id']?>" style="width:50px;" class="category" data-value="<?=$p['category_name']?>"></span>
                    | <span class="tabtext">Опубликован:</span>
                    <select class="visibility" id="<?=$p['article_id']?>" style="font-size:10px;">
                        <option value="<?=$p['visibility']=='yes' ? 'yes':'no'?>"><?=$p['visibility']=='yes' ? 'да':'нет'?></option>
                        <option value="<?=$p['visibility']=='yes' ? 'no' : 'yes' ?>"><?=$p['visibility']=='yes' ? 'нет' : 'да' ?></option>
                    </select>
                    | <span class="tabtext">Просмотров:</span><span id="article_<?=$p['article_id']?>" class="views"><?=$p['views'] == null ? 0 :$p['views'];?></span>
                    | <span class="comm"><img src="/images/comment.png" id="imgcomment" style="vertical-align:middle;padding-right:3px;" title="Комметариев к статье"><span class="tabtext"></span><span id="<?=$p['article_id']?>" class="comments"><?=$p['commcount'] == false ? 0 : $p['commcount'];?></span></span>
                    | <span class="tabtext">Всего голосов:</span><span id="count" class="countvotes"><?=$p['countvote'] ==null ? 0: $p['countvote']; ?></span> |
                    <span class="tabtext">Рейтинг:</span><span id="rating_<?=$p['article_id']?>" class="rating" style="padding:0 5px;margin:0;"><?=$p['sumscore'] !=null ? $p['sumscore'] :0 ?></span><span id="score_<?=$p['article_id']?>" class="score" data-average="<?=$p['sumscore'] !=null ? $p['sumscore'] :0?>" style="float:right;margin:6px 0px 0 5px;"></span>
                </div>
            <?php else:?>
            <?php endif;?>
        <?php endforeach;?>
    </div>
<?php else:?>
    <p style="width:850px;text-align:center;"><strong>Статей не обнаружено.</strong></p>
<?php endif;?>
<div id="progressbar"></div>
<div id="revpages"  data-pagescount="<?=$this->pages?>" style="margin:30px;"></div>